package com.atguigu.algorithm;

import java.util.Arrays;

public class BubbleSort {
    public static void main(String[] args) {
        int[] a=new int[]{78, 79, 18, 70, 75, 37, 81, 29, 38, 88};
        System.out.println(Arrays.toString(a));
        bubbleSort(a);
        System.out.println(Arrays.toString(a));
    }
    public static void bubbleSort(int[] a){
        if(a==null || a.length<2){
            return;
        }
        for(int i=a.length-1;i>=0;i--){
            for(int j=0;j<i;j++){
                if(a[j]<a[j+1]){
                    swap(a,j,j+1);
                }
            }
        }
    }
    public static void swap(int[] a,int i,int j){
        int tmp=a[i];
        a[i]=a[j];
        a[j]=tmp;
    }
}
